;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2022 (unmatched parenthesis <paren@disroot.org>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guixrus packages common ocaml)
  #:use-module (guix build-system dune)
  #:use-module (guix download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (gnu packages ocaml))

(define-public ocaml-pp
  (package
    (name "ocaml-pp")
    (version "1.1.2")
    (source
      (origin
        (method url-fetch)
        (uri "https://github.com/ocaml-dune/pp/releases/download/1.1.2/pp-1.1.2.tbz")
        (sha256
          (base32 "0mhxmzsraid4yw18zr6pyjfrhvf873ls8vfd1yapdfxijs6yk974"))))
    (build-system dune-build-system)
    (native-inputs (list ocaml-ppx-expect))
    (home-page "https://github.com/ocaml-dune/pp")
    (synopsis "Pretty-printing library")
    (description
      "This library provides a lean alternative to the Format [1] module of the OCaml
standard library.  It aims to make it easy for users to do the right thing.  If
you have tried Format before but find its API complicated and difficult to use,
then Pp might be a good choice for you.

Pp uses the same concepts of boxes and break hints, and the final rendering is
done to formatter from the Format module.  However it defines its own algebra
which some might find easier to work with and reason about.  No previous
knowledge is required to start using this library, however the various guides
for the Format module such as this one [2] should be applicable to Pp as well.

[1]: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html [2]:
http://caml.inria.fr/resources/doc/guides/format.en.html")
    (license license:expat)))

(define-public ocaml-ordering
  ;; Part of the dune monorepo.
  (package/inherit dune
    (name "ocaml-ordering")
    (build-system dune-build-system)
    (arguments
      (list #:package "ordering"
            #:tests? #f))
    (native-inputs (list ocaml-odoc))
    (synopsis "Element ordering for OCaml")
    (description "This package provides element ordering for OCaml.")))

(define-public ocaml-dyn
  ;; Part of the dune monorepo.
  (package/inherit dune
    (name "ocaml-dyn")
    (build-system dune-build-system)
    (arguments
      (list #:package "dyn"
            #:tests? #f))
    (propagated-inputs (list ocaml-ordering ocaml-pp))
    (native-inputs (list ocaml-odoc))
    (synopsis "Dynamic type for OCaml")
    (description "This package provides a dynamic type for OCaml.")))

(define-public ocaml-xdg
  ;; Part of the dune monorepo.
  (package/inherit dune
    (name "ocaml-xdg")
    (build-system dune-build-system)
    (arguments
      (list #:package "xdg"
            #:tests? #f))
    (native-inputs (list ocaml-odoc))
    (synopsis "XDG base directories implementation for OCaml")
    (description "This package provides an implementation of XDG base directories
for OCaml.")))

(define-public ocaml-stdune
  ;; Part of the dune monorepo.
  (package/inherit dune
    (name "ocaml-stdune")
    (build-system dune-build-system)
    (arguments
      (list #:package "stdune"
            #:tests? #f))
    (propagated-inputs (list ocaml-csexp ocaml-dyn ocaml-ordering ocaml-pp))
    (native-inputs (list ocaml-odoc))
    (synopsis "Dune utility library")
    (description "This package provides the utility library included with Dune.")))

(define-public ocaml-fiber
  (package/inherit dune
    (name "ocaml-fiber")
    (build-system dune-build-system)
    (arguments
      (list #:package "fiber"
            #:tests? #f))
    (propagated-inputs (list ocaml-dyn ocaml-stdune))
    (native-inputs (list ocaml-odoc))
    (synopsis "Fibers for OCaml")
    (description "This package provides a structured concurrency library for OCaml.")))

(define-public ocaml-dune-rpc
  (package/inherit dune
    (name "ocaml-dune-rpc")
    (build-system dune-build-system)
    (arguments
      (list #:package "dune-rpc"
            #:tests? #f))
    (propagated-inputs (list ocaml-stdune ocaml-xdg))
    (native-inputs (list ocaml-odoc))
    (synopsis "Remotely call Dune")
    (description "This package provides an OCaml library for calling Dune remotely.")))

(define-public ocamlformat-rpc-lib
  (package/inherit ocamlformat
    (name "ocamlformat-rpc-lib")
    (arguments
      (list #:package "ocamlformat-rpc-lib"
            #:tests? #f))
    (synopsis "Remotely call OCamlFormat")
    (description "This package provides an OCaml library for calling OCamlFormat remotely.")))

(define-public ocaml-cinaps
  (package
    (name "ocaml-cinaps")
    (version "0.15.1")
    (source
      (origin
        (method url-fetch)
        (uri "https://github.com/ocaml-ppx/cinaps/archive/v0.15.1.tar.gz")
        (sha256
          (base32 "0w3125jfwckvmd3dx3r0qx7hj9kahdi9nqf3cqsv19nqymq8xq8v"))))
    (build-system dune-build-system)
    (arguments
      ;; XXX The tests seem to try to use a ppx.exe flag that does not exist?
      (list #:tests? #f))
    (propagated-inputs (list ocaml-re))
    (native-inputs (list ocaml-ppx-jane))
    (home-page "https://github.com/ocaml-ppx/cinaps")
    (synopsis "Trivial metaprogramming tool for OCaml")
    (description
      "Cinaps is a trivial metaprogramming tool using the OCaml toplevel.  It is
based on the same idea as expectation tests.  The user writes some OCaml code
inside special comments and cinaps make sure that what follows is what is printed
by the OCaml code.")
    (license license:expat)))

(define-public ocaml-omd
  (package
    (name "ocaml-omd")
    (version "2.0.0-alpha2")
    (source
      (origin
        (method url-fetch)
        (uri "https://github.com/ocaml/omd/releases/download/2.0.0.alpha2/omd-2.0.0.alpha2.tbz")
        (sha256
          (base32 "15kkzil4p38qvvr97fiprgr6imbjci7mg0gbqyxyycjypdprmqxy"))))
    (build-system dune-build-system)
    (arguments
      ;; XXX "Error: Don't know about directory test specified on the command line!"
      (list #:tests? #f))
    (home-page "https://github.com/ocaml/omd")
    (synopsis "Markdown for OCaml")
    (description "This package provides a Markdown library in pure OCaml.")
    (license license:isc)))

(define-public ocaml-ppx-yojson-conv-lib
  (package
    (name "ocaml-ppx-yojson-conv-lib")
    (version "0.15.0")
    (source
      (origin
        (method url-fetch)
        (uri "https://ocaml.janestreet.com/ocaml-core/v0.15/files/ppx_yojson_conv_lib-v0.15.0.tar.gz")
        (sha256
          (base32 "115nlv3apiwsbay6188916zddpf84bnqdcbrygqw2vjnykpwblpr"))))
    (build-system dune-build-system)
    (arguments (list #:tests? #f))
    (propagated-inputs (list ocaml-yojson))
    (properties `((upstream-name . "ppx_yojson_conv_lib")))
    (home-page "https://github.com/janestreet/ppx_yojson_conv_lib")
    (synopsis "Runtime lib for ppx_yojson_conv")
    (description "The Jane Street PPX runtime library for @code{ppx_yojson_conv}.")
    (license license:expat)))
